<?php
/**
 * @Author: lf
 * @Date:   2018-05-11 11:48:59
 * @Last Modified by:   EYong
 * @Last Modified time: 2018-05-14 13:54:15
 */
namespace app\admin\validate;
use think\Validate;

/**
 * 行为验证器
 * @package app\admin\validate
 * @author amplam
 */
class NoteA extends Validate
{
    //定义验证规则
    protected $rule = [
        'notes'      => 'require|notesRule:500',
        'relate_id' => 'require|neq:0',
        'sign_id' => 'require|csign',
        'user_type' => 'notIn:admin,plat',
    ];

    //定义验证提示
    protected $message = [
        'notes.require' => '不能输入空的模板',
        'sign_id'       => '请选择签名模板',
        'relate_id'     => '当前账号未绑定渠道',
        'user_type'     => '当前账号未绑定渠道',
    ];
	//验证场景
    protected $scene = [
        'edt' => ['notes','sign_id.require'],
        'add' => ['notes','relate_id','sign_id','user_type']
    ];

    // 自定义验证规则
    protected function notesRule($value,$rule)
    {
        $num = mb_strlen($value, 'UTF-8');
        if($num > $rule )
        {
            return "字数过多";
        }
       return true;
    }
    // 自定义验证规则
    protected function neq($value,$rule)
    {
        if ($value == $rule) {
            return "当前账号未绑定渠道";
        } else {
            return true;
        }
    }
    // 自定义验证规则
    protected function csign($value,$rule)
    {

        $preg = '/^【.*】$/';
        if( preg_match($preg,$value) ){
            return true;
        }

        return "签名验证不通过";
    }

}